<template>
  <div id="login">
    <h1>ADMIN USER LOGIN</h1>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="loginForm">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="ruleForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="ruleForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="button" type="primary" @click="submitForm('ruleForm')">登录</el-button>
        <el-button class="button" @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur'}
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:8080/login';
          console.log(this.ruleForm);
          this.axios.post(url, this.ruleForm).then(res => {
            if (res.data == 1) {
              this.$message({
                message: '恭喜你，登录成功！',
                type: 'success'
              });
            } else if (res.data == 2) {
              this.$notify.error({
                title: 'error',
                duration: 2000,
                message: '账号或密码错误'
              });
            }
          });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style>

#login {
  width: 100%;
  height: 100%;
  position: fixed;
  background-image: url("../../assets/static/bkm.jpg");
  background-size: 100% 100%;
  text-align: center;
}

#login > h1 {
  color: #0a6681;
  margin: 180px auto 120px auto;
}

#login .button {
  background-color: rgba(255, 255, 255, 0.05);
  color: #0a6681;
  border: 1px solid transparent;
}

#login .label {
  background-color: rgba(255, 255, 255, 0.05);
  color: #0a6681;
  border: 1px solid transparent;
}

.loginForm {
  width: 350px;
  margin: auto auto 200px auto;
  padding: 35px 120px 15px 25px;
  border: 1px solid transparent;
  border-radius: 15px;
  background-color: rgba(255, 255, 255, 0.1);
  box-shadow: 5px 5px 0 0 rgba(0, 0, 0, 0.2);
  position: relative;
  left: -15px;
}

#from > h1 {
  margin: 100px auto;
}

.el-textarea__inner, .el-input__inner {
  background: transparent !important;
}
</style>